#include "ide.h"
#include "mimainwindow.h"
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <QKeySequence>
#include <QStatusBar>

//Internal functions
void buildFileMenu( MIMainWindow* app );
void buildEditMenu( MIMainWindow* app );
void buildHelpMenu( MIMainWindow* app );
void buildBuildMenu( MIMainWindow* app );
void buildToolsMenu( MIMainWindow* app );

MIPluginList* findPlugins( bool plugins_enabled )
{
    return 0;
}

MIMainWindow* loadGUI( QApplication& app )
{

   MIMainWindow* mw = new MIMainWindow();



   buildFileMenu( mw );
   buildEditMenu( mw );
   buildBuildMenu( mw );
   buildToolsMenu( mw );
   buildHelpMenu( mw );

   mw->statusBar()->showMessage( mw->tr("Initialized \"MuddyIDE\" on /dev/deadBadger0"), 0 );

   return mw;

}

void buildFileMenu( MIMainWindow* app )
{
    QMenu* fm = app->menuBar()->addMenu(app->tr("&File"));

    fm->addAction( QIcon(":/images/gs.png"), app->tr("Getting Started..."), app, SLOT(gettingStartedTab()) );

    fm->addSeparator();

    fm->addAction( QIcon(":/images/document-new.png"), app->tr("New File"), app, SLOT(slotNewTab()), QKeySequence(app->tr("CTRL+N")));
    fm->addAction( QIcon(":/images/document-open.png"), app->tr("Open File..."), app, SLOT(slotOpenFile()), QKeySequence(app->tr("Ctrl+O")));

    fm->addSeparator();

    fm->addAction( QIcon() /*QIcon(":/images/newproj.png")*/, app->tr("New Project..."), app, SLOT(slotNewProject()), QKeySequence(app->tr("Shift+Ctrl+N")));
    fm->addAction( QIcon() /*QIcon(":/images/openpro.pnt")*/, app->tr("Open Project..."), app, SLOT(slotOpenProject()), QKeySequence(app->tr("Shift+Ctrl+O")));

    fm->addSeparator();

    fm->addAction( QIcon(":/images/file-close.png"), app->tr("Close Tab"), app, SLOT(slotCloseCurrentTab(bool)), QKeySequence(app->tr("Ctrl-W")));
    fm->addAction( QIcon(":/images/file-quit.png"), app->tr("Exit MuddyIDE"), app, SLOT(close()), QKeySequence("Alt-F4"));



}

void buildEditMenu( MIMainWindow* app )
{
    QMenu* em = app->menuBar()->addMenu(app->tr("&Edit"));

    em->addAction( QIcon(":/images/edit-undo.png"), app->tr("Undo"), app, SLOT(slotUndo()), QKeySequence(app->tr("Ctrl+Z")) );
    em->addAction( QIcon(":/images/edit-redo.png"), app->tr("Redo"), app, SLOT(slotRedo()), QKeySequence(app->tr("Ctrl+Y")) );

    em->addAction( QIcon(":/images/edit-cut.png"), app->tr( "C&ut" ), app, SLOT(slotCut()), QKeySequence(app->tr("Ctrl+X")) );
    em->addAction( QIcon(":/images/edit-copy.png"), app->tr( "&Copy" ), app, SLOT(slotCopy()), QKeySequence(app->tr("Ctrl+C")) );
    em->addAction( QIcon(":/images/edit-paste.png"), app->tr( "&Paste" ), app, SLOT(slotPaste()), QKeySequence(app->tr("Ctrl+V")) );

    em->addSeparator();

    em->addAction( QIcon(":/images/edit-find.png"), app->tr( "&Find..." ), app, SLOT(slotFind()), QKeySequence(app->tr("Ctrl+F")) );
    em->addAction( QIcon(":/images/edit-find-next.png"), app->tr( "Find &Next" ), app, SLOT(slotFindNext()), QKeySequence(app->tr("Shift+Ctrl+F")) );

    em->addSeparator();

    em->addAction( app->tr( "&Options..." ), app, SLOT(slotOptions()) );
}

void buildHelpMenu( MIMainWindow* app )
{
    QMenu* hm = app->menuBar()->addMenu(app->tr("&Help"));

    hm->addAction( app->tr( "MuddyIDE Help"), app, SLOT(slotAppHelp()) );

    hm->addSeparator();

    hm->addAction( app->tr("Add Help File..."), app, SLOT(slotAddHelpFile()) );

    hm->addSeparator();

    hm->addAction( app->tr( "About MuddyIDE"), app, SLOT(slotAboutMI()) );


}

void buildBuildMenu( MIMainWindow* app )
{
    QMenu* bm = app->menuBar()->addMenu(app->tr("&Build"));

    bm->addAction( QIcon(":/images/build-compile.png"), app->tr("Compile"), app, SLOT(slotCompile()) );
    bm->addAction( QIcon(":/images/build-run.png"), app->tr("Run"), app, SLOT(slotRun()) );
    bm->addAction( app->tr("Quick Run"), app, SLOT(slotQuickRun()), QKeySequence(app->tr("F5")) );

    bm->addSeparator();

    QMenu* bmco = bm->addMenu( app->tr("Compile Options") );

        app->debugCompile = new QAction( app->tr("Include Debugging Symbols"), bmco );
        app->debugCompile->setCheckable( true );
        bmco->addAction( app->debugCompile );

        app->profileCompile = new QAction( app->tr("Include Profiling Support"), bmco );
        app->profileCompile->setCheckable( true );
        bmco->addAction( app->profileCompile );

        app->warningCompile = new QAction( app->tr("Show All Warnings"), bmco );
        app->warningCompile->setCheckable( true );
        bmco->addAction( app->warningCompile );

        app->eCompile = new QAction( app->tr("Add Basic Error Checking"), bmco );
        app->eCompile->setCheckable( true );
        bmco->addAction( app->eCompile );

        app->exCompile = new QAction( app->tr("Add Error Checking with RESUME support"), bmco );
        app->exCompile->setCheckable( true );
        bmco->addAction( app->exCompile );

        app->exxCompile = new QAction( app->tr("Add Null ptr and OOB Array checks"), bmco );
        app->exxCompile->setCheckable( true );
        bmco->addAction( app->exxCompile );

    bm->addSeparator();

    bm->addAction( app->tr("Run Options..."), app, SLOT(slotRunOptions()) );

    bm->addSeparator();

    QMenu* bmbc = bm->addMenu( app->tr("External Build Command") );

    bmbc->addAction( app->tr("Make"), app, SLOT(slotExtMake()) );
    bmbc->addAction( app->tr("Make Clean"), app, SLOT(slotExtMakeClean()) );

    bmbc->addSeparator();

    bmbc->addAction( app->tr("Manage Build Tools..."), app, SLOT(slotBuildToolOptions()) );
}

void buildToolsMenu( MIMainWindow* app )
{
    QMenu* tm = app->menuBar()->addMenu( app->tr("Tools") );

    //add menu choices from plugins/scripts here

    tm->addSeparator();

    QAction* cur = tm->addAction( app->tr("Manage Plugins"), app, SLOT(slotManagePlugins()) );

    cur->setEnabled( false );

}
